import {Injectable} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {Observable} from 'rxjs/Observable';

@Injectable()
export class RoleService {

    url_rolelist = 'Role/list';
    url_addrole = 'Role/save';
    url_delrole = 'Role/del/';
    url_showrole = 'Role/show/';

    constructor(private http: _HttpClient) {
    }

    /**
     * 获取角色列表
     * @returns {Observable<{}>}
     */
    getRoleList(): Observable<{}> {
        return this.http.get(this.url_rolelist);
    }

    /**
     * 删除角色
     * @param {string} id
     * @returns {Observable<string>}
     */
    delRole(id: string): Observable<{}> {
        return this.http.delete(this.url_delrole + id);
    }

    /**
     * 添加/修改角色
     * @param i
     * @returns {Observable<string>}
     */
    addRole(i): Observable<string> {
        const xx = {
            id: i.id ? i.id : 0,
            resId: i.resId,
            nickName: i.nickName,
        };
        return this.http.post<string>(this.url_addrole, JSON.stringify(xx));
    }

    /**
     * 显示角色详情
     * @param {string} id
     * @returns {Observable<{}>}
     */
    showRole(id: string): Observable<{}> {
        return this.http.get(this.url_showrole + id);
    }

}
